/*
 Copyright (c) Whitemice Consulting, 2007, 2008, 2009
 Adam Tauno Williams <awilliam@whitemice.org>
 License: MIT/X11

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
*/
using System;

namespace Whitemice.ZOGI
{
	public enum ServerEventType : uint 
	{
    Create = 0,
    Update = 1,
    SubordinateChange = 2,
    Delete = 3
	}
	
	public enum ServerEventPriority : uint
	{
	  Low = 0,
	  Normal = 1,
	  High = 2,
	  Immediate = 3
	}

  public class ServerEvent
	{
		protected Entity 					                    entity;
		protected ServerEventType	                    eventType;
		protected DateTime				                    time;
		protected int                                 id;
		protected ServerEventPriority                 priority;
		
		public ServerEvent(Entity entity, ServerEventType eventType)
      : this(entity, eventType, ServerEventPriority.Normal)
		{
		}
		
		public ServerEvent(Entity entity, 
		                   ServerEventType eventType, 
		                   ServerEventPriority priority)
		{
			this.entity = entity;
			this.eventType = eventType;
			this.priority = priority;
			time = DateTime.Now;
			priority = ServerEventPriority.Normal;
			id = Server.InternalId;
		} // end ServerEvent
		
		public Entity Entity { get { return entity; } }
		public ServerEventType Event { get { return eventType; } }
		public DateTime Time { get { return time; } }
		
		public ServerEventPriority Priority 
		{ 
		  get { return priority; }
		  set { priority = value; }
		} // end Priority
		
		public override string ToString()
		{
		  return "EventId#" + id.ToString() + " " +
		    entity.ToString() + " " + EventString();
		} // end ToString
		
		protected string EventString()
		{
		  switch(Event)
		  {
		    case ServerEventType.Create: return "Created";
		    case ServerEventType.Delete: return "Deleted";
		    case ServerEventType.SubordinateChange: return "SubordinateChange";
		    case ServerEventType.Update: return "Update";
		    default: return "Undefined";
		  } /// end switch-event-type
		} // end EventString
	} // end ServerEvent
} // end namespace

